import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		ip:'http://122.228.189.214:18099/',
		/**
		 * 是否需要强制登录
		 */
		forcedLogin: false,
		hasLogin: false,
		userName: "",
		token:'',
		refreshToken:'',
	},
	mutations: {
		login(state, data) {
			state.userName = data.username || '新用户';
			state.hasLogin = true;
			state.token = data.token;
			state.refreshToken = data.refreshToken;
			try {
			    uni.setStorageSync('data', data);
			} catch (e) {
			    // error
			}
			
		},
		logout(state) {
			state.userName = "";
			state.token = '';
			state.refreshToken = '';
			state.hasLogin = false;
			uni.removeStorage({
				key:'data'
			});
		}
	}
})

export default store
